﻿using System.Web.Mvc;
using Scribble.Services;

namespace Scribble.Web.Controllers
{
    public class PostController : Controller
    {
        private readonly IPostService postService;
        private readonly ITagService tagService;
        private readonly ICategoryService categoryService;

        public PostController(IPostService postService, ITagService tagService, ICategoryService categoryService)
        {
            this.postService = postService;
            this.tagService = tagService;
            this.categoryService = categoryService;
        }

        public ActionResult Index()
        {
            var posts = postService.GetPosts();

            return View(posts);
        }

        public ActionResult Get(int year, int month, string urlTitle)
        {
            var post = postService.GetPost(year, month, urlTitle);

            return View(post);
        }

        public ActionResult ListByTag(string urlTitle)
        {
            var tag = tagService.GetByTitle(urlTitle);
            var posts = postService.GetPostsByTag(tag);

            return View(posts);
        }

        public ActionResult ListByCategory(string urlTitle)
        {
            var category = categoryService.GetByTitle(urlTitle);
            var posts = postService.GetPostsByCategory(category);

            return View(posts);
        }
    }
}